﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLayer.BLServerReference;
using BusinessLayer;

namespace WebFrontEnd
{
    public partial class ConfirmEmail : System.Web.UI.Page
    {
        private IBL _bl;

        private IBL BL 
        {
            get
            {
                if (_bl == null)
                {
                    _bl = BusinessLayerFactory.GetCurrentBusinessLayer("");   
                }
                return _bl;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            string id = Request["id"];
            string hash = Request["h"];
            int idNum = 0;
            if (id == null || hash == null || !int.TryParse(id,out idNum))
            {
                Response.Redirect("Login.aspx");
            }
            if (User.Identity.IsAuthenticated)
            {
                FormsAuthentication.SignOut();
            }
            if (BL.ValidateActivationHash(hash, idNum) != null)
            {
                Session["flash"] = YorKinHTMLHelper.CreateBootstrapAlert("You have successfully activated your YEMS! account, enjoy :)", "alert-success");
            }
            else
            {
                Session["flash"] = YorKinHTMLHelper.CreateBootstrapAlert("Your activation link was not valid.", "alert-error");
            }
            Response.Redirect("Login.aspx");
        }
    }
}